package com.example.socialwebserver.controller;

import com.example.socialwebserver.pojo.*;
import com.example.socialwebserver.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class FriendController {
    @Autowired
    FriendService friendService;


    @RequestMapping("friend/SelectById")
    public ServerResult SelectById(Integer id){
        List<FriendVO> friendVOList = friendService.SelectById(id);
        ServerResult serverResult = new ServerResult(0,"成功",friendVOList);
        return serverResult;
    }

    /**
     * 根据自己的id和想要关注的用户的id来添加关注关系
     * @param friendDTO
     * @return如果关注成功返回true，否则返回false
     */
    @RequestMapping("friend/InsertById")
    public ServerResult InsertById(FriendDTO friendDTO){
        boolean b = friendService.InsertById(friendDTO);
        if(b == true){
            return new ServerResult(0,"关注id为" + friendDTO.getFriendId() + "的用户成功",b);
        }else{
            return new ServerResult(0,"关注id为" + friendDTO.getFriendId() + "的用户失败",b);
        }
    }

    /**
     * 根据自己的id以及好友的id删除关注关系
     * @param friendDTO
     * @return如果删除成功返回true，否认返回false
     */
    @RequestMapping("friend/DeleteById")
    public ServerResult DeleteById(FriendDTO friendDTO){
        boolean b = friendService.DeleteById(friendDTO);
        if(b == true){
            return new ServerResult(0,"取关id为" + friendDTO.getFriendId() + "的用户成功",b);
        }else{
            return new ServerResult(0,"取关id为" + friendDTO.getFriendId() + "的用户失败",b);
        }
    }
}
